!------------------------------------------------------------------------------
! TJU/Department of Mechanics, Fluid Mechanics, Code START
!------------------------------------------------------------------------------
!> @Author: Jianxin Liu shookware@tju.edu.cn
!> @Date: 2024-12-05 13:34:12
!> @LastEditTime: 2024-12-05 13:38:27
!> @LastEditors: Jianxin Liu shookware@tju.edu.cn
!> @Description:
!> @FilePath: /chem/test/chem_load.f90
!> @Copyright (c) 2024 by Jianxin Liu email: shookware@tju.edu.cn, All Rights Reserved.
!------------------------------------------------------------------------------
program chem_load_test

   use mod_chem
   use iso_fortran_env, only: dp => real64

   type(type_chem_phases) :: phases
   real(dp), allocatable :: molecular_weights(:)

   integer :: i, j, k

   phases = chem_file_load("air_5species_NASA9.yaml", "air")
   print *, "Elements:", phases%n_elements
   do i = 1, size(phases%elements)
      write (*, "(1X, A4)", advance="no") phases%elements(i)%name
   end do
   write (*, *)
   print *, "Species:", phases%n_species
   do i = 1, size(phases%species)
      write (*, "(1X, A4)", advance="no") phases%species(i)%name
   end do
   write (*, *)
   print *, "check species:"
   molecular_weights = phases%get_molecular_weights()
   do i = 1, phases%n_species
      write (*, "(1X, A)") phases%species(i)%name
      write (*, "(5X, A)") "composition:"
      do j = 1, phases%n_elements
         write (*, "(5X, A, 5X, I4)") phases%elements(j)%name, phases%species(i)%composition(j)
      end do
      write (*, "(5X, A, 5X, F10.3)") "molecular weight:", molecular_weights(i)
      write (*, "(5X, 2A)") "thermo_model:", phases%species(i)%thermo%name
      write (*, "(5X, A, 6(2X, F10.3))") "temperature-ranges:", phases%species(i)%thermo%temperature_ranges
      do k = 1, size(phases%species(i)%thermo%temperature_ranges) - 1
         write (*, "(5X, 12G15.5)") phases%species(i)%thermo%coefficients(:, k)
      end do
      write (*, "(5X, 12G15.5)") phases%species(i)%thermo%h0, "J/kmol", "@", phases%species(i)%thermo%T0, "K"
      write (*, "(5X, 12G15.5)") phases%species(i)%thermo%delta_h0, "J/kmol"
      write (*, "(5X, 2A)") "viscosity_coefficients:"
      write (*, "(5X, 12G15.5)") phases%species(i)%transport%viscosity_coefficients
      write (*, "(5X, 2A)") "thermal_conductivity_coefficients:"
      write (*, "(5X, 12G15.5)") phases%species(i)%transport%thermal_conductivity_coefficients

   end do
   write (*, *)
   print *, "check reactions:"
   write (*, "(1X, A, I5)") "reactions_number = ", phases%n_species
   do i = 1, phases%n_reactions
      write (*, "(1X, A)") phases%reactions(i)%equation
      write (*, "(5X, 2A)") "type:", phases%reactions(i)%type
      write (*, "(5X, A)") "rate-constant"
      write (*, "(5X, 12G15.5)") "A:", phases%reactions(i)%A, phases%reactions(i)%A_unit
      write (*, "(5X, 12G15.5)") "b:", phases%reactions(i)%b, phases%reactions(i)%b_unit
      write (*, "(5X, 12G15.5)") "Ea:", phases%reactions(i)%Ea, phases%reactions(i)%Ea_unit
      if (phases%reactions(i)%type == "three-body") then
         write (*, "(5X, 20G15.5)") (phases%species(j)%name, phases%reactions(i)%efficiencies(j), j=1, phases%n_species)
      end if
      write (*, "(5X, A)") "stoichiometric_number:"
      write (*, "(5X, A, 10I4)") "forward:", phases%reactions(i)%sto_num_fwd
      write (*, "(5X, A, 10I4)") "backward:", phases%reactions(i)%sto_num_rev
   end do
end
